package com.liming.common.enums;

import cn.hutool.core.util.ObjectUtil;
import com.liming.common.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @author liming
 * @date 2025/4/2
 */
@Getter
@AllArgsConstructor
public enum MiniOrderQueryStatusEnum {

    // 0 全部、1 待付款、2 待发货、3 待收货、4 待自提、5 待评价、6 退款/售后
    ALL(0, "全部"),
    UNPAID(1, "待付款"),
    UNSHIPPED(2, "待发货"),
    UNRECEIVED(3, "待收货"),
    UNPICKED(4, "待自提"),
    UNCOMMENTED(5, "待评价"),
    REFUND_AFTER_SALE(6, "退款/售后");

    private final Integer code;
    private final String desc;

    public static List<Integer> statusByQueryStatus(Integer queryStatus) {
        if (ObjectUtil.equal(queryStatus, ALL.getCode())) {
            return Arrays.stream(OrderStatusEnum.values()).map(OrderStatusEnum::getCode).toList();
        } else if (ObjectUtil.equal(queryStatus, UNPAID.getCode())) {
            // 待付款
            return List.of(OrderStatusEnum.UNPAID.getCode());
        } else if (ObjectUtil.equal(queryStatus, UNSHIPPED.getCode())) {
            // 待发货
            return List.of(OrderStatusEnum.PAID.getCode(), OrderStatusEnum.WAITING_FOR_DELIVERY.getCode());
        } else if (ObjectUtil.equal(queryStatus, UNRECEIVED.getCode())) {
            // 待收货
            return List.of(OrderStatusEnum.DELIVERED.getCode());
        } else if (ObjectUtil.equal(queryStatus, UNPICKED.getCode())) {
            // 待自提
            return List.of(OrderStatusEnum.WAITING_FOR_PICKUP.getCode());
        } else if (ObjectUtil.equal(queryStatus, UNCOMMENTED.getCode())) {
            // 待评价
            return List.of(OrderStatusEnum.COMPLETED.getCode());
        } else if (ObjectUtil.equal(queryStatus, REFUND_AFTER_SALE.getCode())) {
            // 退款/售后
            return List.of(OrderStatusEnum.UN_REFUNDED.getCode(), OrderStatusEnum.REFUNDED.getCode());
        }
        throw new BusinessException("订单状态查询异常");
    }
}
